<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="商品模板详情">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }
        .layui-table-view{
            margin: 0;
        }
    </style>

    <script>
        jQuery(function () {

            $("#cancel").click(function () {
                closeSubIframe();
            });


        });

        layui.use(['form', 'table'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                util = layui.util;


            get("${baseUrl}marketGoods/goodsTemplate/getVoById.action?id=${id}", function (res) {
                if (res.code == 1) {
                    $("#print").click(function () {
                        document.getElementById("printFrame").contentWindow.printPage(res.data);
                    });

                    $("#no").html(res.data.no);

                    $("#name").html(res.data.name);
                    $("#no").html(res.data.no);
                    $("#remark").html(res.data.remark);
                    if (res.data.status == 1) {
                        $("#status").html("启用");
                    } else {
                        $("#status").html("停用");
                    }
                    let list=[];
                    $.each(res.data.goodsTemplateGoodsVoList, function (i,d) {
                        let vo = d.goodsVo;
                        vo.goodsId = d.goodsId;
                        vo.number = d.number;
                        vo.unitId = d.unitId;
                        vo.times = d.times;
                        list.push(vo);
                    });
                    renderTable(list);
                }
            });
        });

        function renderTable(goodsList) {

            layui.use(['form', 'table'], function () {
                let $ = layui.jquery,
                    table = layui.table;
                table.render({
                    id: 'table',
                    elem: '#table',
                    data: goodsList,
                    text: {
                        none: '未选择商品' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                    },
                    cols: [[
                        {type: 'numbers'},
                        {field: 'name', minWidth: 140, title: '名称/规格', style: "font-size:12px;", templet: function (d) {
                                return genGoodsName(d.name,d.norms);
                            }},
                        {field: 'no', width: 140, title: '商品编号', style: "font-size:12px;"},
                        {field: 'number',width: 110, title: '数量', templet: function (d) {
                                return getNumber(d.number);
                            }},
                        {width: 120, title: '单位', style: "font-size:12px;", templet: function (d) {
                                return genUnitName(d.goodsUnitVoList,d.unitId);
                            }},
                    ]],
                    limit: Number.MAX_VALUE,
                    done: function (res, curr, count) {
                    }
                });
            });
        }
    </script>

</html:header>
<body>

<div class="layui-inline" style="padding-bottom: 20px;">
    <button class="layui-btn" id="print">打印</button>
    <button class="layui-btn layui-btn-primary" id="cancel">关闭</button>
</div>

<iframe id="printFrame" style="width:0px;height:0px" src="${baseUrl}print/goodsTemplatePrint.action" frameborder="0"></iframe>

<div class="layuimini-container">
    <div class="layuimini-main">

        <h2 class="tableBeforeTitle">商品模板</h2>
        <div style="height: 4px;background-color: #bbbbbb;width: 100%;margin: 20px 0 2px 0;"></div>
        <div style="height: 1px;width: 100%;background-color: #dddddd;margin-bottom: 10px;"></div>
        <div style="height: 10px;"></div>

        <form class="layui-form" lay-filter="packetForm" action="">
            <input type="hidden" name="id">
            <button style="display: none;" lay-submit lay-filter="save" class="layui-btn">保存</button>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">编号：</span>
                    <span id="no" name="no"></span>
                </div>
            </div>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <span style="color: #aaaaaa">名称：</span>
                <span id="name" ></span>
            </div>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">状态：</span>
                    <span id="status"></span>
                </div>
            </div>

            <div style="height: 20px;"></div>

            <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>

            <table class="layui-table" style="margin: -1px 0 0 0;">
                <colgroup>
                    <col width="60">
                    <col>
                </colgroup>
                <tbody>
                <tr>
                    <td>备注</td>
                    <td>
                        <span id="remark" style="color: #aaaaaa"></span>
                    </td>
                </tr>
                </tbody>
            </table>

        </form>
    </div>
</div>
</body>
</html>